package org.demo.hdfs.config;

import java.net.URI;
import org.apache.hadoop.fs.FileSystem;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FusionHadoopConfig {

	
	@Bean
	@ConditionalOnMissingBean(FusionHadoopProperties.class)
	public FusionHadoopProperties fusionHadoopProperties() {
		return new FusionHadoopProperties();
	}
	
	@Bean
	public FileSystem fileSystem() throws Exception {
		FusionHadoopProperties fusionHadoopProperties = fusionHadoopProperties();
		String url = fusionHadoopProperties.getUrl();
		url="hdfs://"+url;
		String username = fusionHadoopProperties.getUsername();
		org.apache.hadoop.conf.Configuration configurationhadoop = new org.apache.hadoop.conf.Configuration();
		return FileSystem.get(new URI(url), configurationhadoop,username);
	}
}
